//
//  CareDataSource.m
//  tcpoctest
//
//  Created by gump on 4/10/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "CareDataSource.h"

@implementation CareDataSource
{
    
}

-(id)init
{
    self = [super init];
    if (self != nil) {
        pthread_mutex_init(&mmutex, 0);
        showarr = [[NSMutableArray alloc] init];
        mcarelength = 0;
        mTobeRead = 0;
    }
    
    return self;
}

-(void)SetCareLength:(int)length
{
    pthread_mutex_lock(&mmutex);
    
    mcarelength = length;
    
    pthread_mutex_unlock(&mmutex);
}

-(int)GetCareLenght
{
    return mcarelength;
}

-(int)GetShowArrCount
{
    return [showarr count];
}

-(void)RemoveAllShowArr
{
    pthread_mutex_lock(&mmutex);
    
    [showarr removeAllObjects];
    
    pthread_mutex_unlock(&mmutex);
}

-(int)GetTobeRead
{
    return mTobeRead;
}

-(void)SetTobeRead:(int)iread
{
    pthread_mutex_lock(&mmutex);
    
    mTobeRead = iread;
    
    pthread_mutex_unlock(&mmutex);
}

-(void)AddShowArrObject:(NSString *)mail
{
    pthread_mutex_lock(&mmutex);
    
    if (![showarr containsObject:mail]) {
        [showarr addObject:mail];
    }
    
    pthread_mutex_unlock(&mmutex);

}

-(NSString *)GetShowArrObjectByIndex:(int)index
{
    NSString *str = @"";
    
    pthread_mutex_lock(&mmutex);
    
    if (index >= 0 && index < [showarr count]) {
        str = [showarr objectAtIndex:index];
    }
    
    pthread_mutex_unlock(&mmutex);
    
    return str;
}

-(bool)IsShowArrContainsObject:(NSString *)mail
{
    bool bcontains = false;
    
    pthread_mutex_lock(&mmutex);
    
    if ([showarr containsObject:mail] == YES) {
        bcontains = true;
    }
    
    pthread_mutex_unlock(&mmutex);
    
    return bcontains;
}

-(void)InSertShowArrObject:(NSString *)mail withIndex:(int)index
{
    pthread_mutex_lock(&mmutex);
    
    [showarr insertObject:mail atIndex:index];
    
    pthread_mutex_unlock(&mmutex);
}

-(void)RemoveShowArrObject:(NSString *)mail
{
    pthread_mutex_lock(&mmutex);
    
    [showarr removeObject:mail];
    
    pthread_mutex_unlock(&mmutex);
}

@end
